package com.rybbaby.tss.tasks.core.task.service.imp;

import com.rybbaby.tss.tasks.core.task.dao.ITssMemberPackageDao;
import com.rybbaby.tss.tasks.core.task.entity.TssMemberPackage;
import com.rybbaby.tss.tasks.core.task.service.ITssMemberPackageService;
import com.rybbaby.tss.tasks.core.web.service.imp.BaseServiceImp;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author 雷春琼
 * @description 会员课时包数据库操作服务实现
 * @createDate 2017-08-10 上午12:04:35
 */
@Service
@Transactional
public class TssMemberPackageServiceImp extends BaseServiceImp<TssMemberPackage> implements ITssMemberPackageService {

    @Autowired
    private ITssMemberPackageDao tssMemberPackageDao;


    @Override
    public boolean deductiveHours(List<Map<String, Object>> attendance) {
        ArrayList<Object[]> params = new ArrayList<>();
        for (Map<String, Object> param : attendance) {
            int expendClassHour = (int) param.get("expendClassHour");
            String memberPackageId = (String) param.get("memberPackageId");
            params.add(new Object[]{expendClassHour,expendClassHour,memberPackageId});
        }
        return tssMemberPackageDao.deductiveHours(params);
    }

    @Override
    public boolean remediationClassHour(List<Map<String, Object>> attendance) {
        ArrayList<Object[]> params = new ArrayList<>();
        for (Map<String, Object> param : attendance) {
            int expendClassHour = (int) param.get("expendClassHour");
            String memberPackageId = (String) param.get("memberPackageId");
            params.add(new Object[]{expendClassHour,expendClassHour,expendClassHour,memberPackageId});
        }
        return tssMemberPackageDao.remediationClassHour(params);
    }

    @Override
    public boolean transitionAttendance(List<Map<String, Object>> transitionAttendance) {
        ArrayList<Object[]> params = new ArrayList<>();
        for (Map<String, Object> param : transitionAttendance) {
            String memberPackageId = (String) param.get("memberPackageId");
            params.add(new Object[]{memberPackageId});
        }
        return tssMemberPackageDao.transitionAttendance(params);
    }

    @Override
    public boolean absentDays(List<Map<String, Object>> absentDays) {
        ArrayList<Object[]> params = new ArrayList<>();
        for (Map<String, Object> param : absentDays) {
            String memberPackageId = (String) param.get("memberPackageId");
            params.add(new Object[]{memberPackageId});
        }
        return tssMemberPackageDao.absentDays(params);
    }

    @Override
    public Integer updatePackageValidity() {
        return tssMemberPackageDao.updatePackageValidity();
    }

}
